﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using AircraftBattleServer;
using System.Media;

namespace AircraftBattleClient
{
    /// <summary>
    /// Interaction logic for GameEnd.xaml
    /// </summary>
    public partial class GameEnd : Window
    {
        private SoundPlayer sndWin = new SoundPlayer(Constants.SoundFolderRelativePath
                + "\\" + "Win.wav");
        private SoundPlayer sndLose = new SoundPlayer(Constants.SoundFolderRelativePath
                + "\\" + "Lose.wav");

        public GameEnd(User u, int winner)
        {
            GameEngineServiceClient clt = new GameEngineServiceClient();
            InitializeComponent();

            if (winner == 3)
            {
                this.lblResult.Content = "A draw game. ";
            }
            else if (u.team == winner)
            {
                sndWin.Play();
                this.lblResult.Content = "Congratulations! Your team wins.";
                clt.AddWinRecord(u.userName);
            }
            else
            {
                sndLose.Play();
                this.lblResult.Content = "You lose the game.";
                clt.AddLoseRecord(u.userName);
            }

            int win = clt.GetWinRecord(u.userName);
            int lose = clt.GetLoseRecord(u.userName);

            this.lblLoses.Content = "Loses: " + lose;
            this.lblWins.Content = "Wins: " + win;
        }

        private void btnQuit_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }

        private void btnRematch_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }
    }
}
